package com.cnsunrun.commonui.utils;

import android.content.Context;
import android.view.WindowManager;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

/**
 * @作者:TJ
 * @时间:2019/7/25 16:09
 * @描述:
 */
public class Tools {

    /**
     * 是否为手机号
     *
     * @param str
     * @return
     * @throws PatternSyntaxException
     */
    public static boolean isChinaPhoneLegal(String str)
            throws PatternSyntaxException {
        String  regExp = "^((13[0-9])|(15[^4])|(18[0-9])|(17[0-8])|(147,145))\\d{8}$";
        Pattern p      = Pattern.compile(regExp);
        Matcher m      = p.matcher(str);
        return m.matches();
    }

    /**
     * 正则匹配图片头
     * @param str
     * @return
     * @throws PatternSyntaxException
     */
    public static boolean matcheImageFormat(String str)
            throws PatternSyntaxException {
        String  regExp = "/^data:(.*);(.*),(.*)$/";
        Pattern p      = Pattern.compile(regExp);
        Matcher m      = p.matcher(str);
        return m.matches();
    }


    /**
     * 判断密码复杂度以及长度
     *
     * @param str
     * @return
     */
    public static boolean isValidPassword(String str) {
        if (str.length() < 6 || str.length() > 30) {
            return false;
        }
        String  regExp = "^^(?![a-zA-z]+$)(?!\\\\d+$)(?![!@#$%^&*_-]+$)(?![a-zA-z\\\\d]+$)(?![a-zA-z!@#$%^&*_-]+$)(?![\\\\d!@#$%^&*_-]+$)[a-zA-Z\\\\d!@#$%^&*_-]+$";
        Pattern p      = Pattern.compile(regExp);
        Matcher m      = p.matcher(str);
        return m.matches();
    }


    /**
     * 获取屏幕分辨率
     *
     * @param context
     * @return
     */
    @SuppressWarnings("deprecation")
    public static int[] getScreenDispaly(Context context) {
        WindowManager windowManager = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
        int width    = windowManager.getDefaultDisplay().getWidth();// 手机屏幕的宽度
        int height   = windowManager.getDefaultDisplay().getHeight();// 手机屏幕的高度
        int result[] = {width, height};
        return result;
    }

    /**
     * 判断空
     *
     * @param s
     * @return
     */
    public static boolean isEmpty(String s) {
        return s == null || s.isEmpty();
    }
}
